package com.hangim.pce.enums;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 规则类型
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum RuleType {
    PEOPLE("PEOPLE", 1, "人群"),
    COMPATE("COMPATE", 2, "配伍禁忌"),
    USAGE("USAGE", 3, "用法"),
    INTERACTION("INTERACTION", 4, "相互作用"),
    REPEAT_DOSING("REPEAT_DOSING", 5, "重复给药"),
    OTHER("OTHER", 0, "其他");

    // 类型
    private final String code;
    // 描述
    private final String desc;

    private final Integer num;

    RuleType(final String code, final Integer num, final String desc) {
        this.code = code;
        this.desc = desc;
        this.num = num;
    }

    public static Boolean isPeople(String desc) {
        RuleType[] ts = RuleType.values();
        if (PEOPLE.getDesc().contains(desc)) {
            return true;
        }
        return false;
    }

    public static Boolean isUsage(String desc) {
        RuleType[] ts = RuleType.values();
        if (USAGE.getDesc().contains(desc)) {
            return true;
        }
        return false;
    }

    public static Boolean isCompate(String desc) {
        RuleType[] ts = RuleType.values();
        if (COMPATE.getDesc().contains(desc)) {
            return true;
        }
        return false;
    }

    public static Boolean isRepeatDosing(String desc) {
        RuleType[] ts = RuleType.values();
        if (REPEAT_DOSING.getDesc().contains(desc)) {
            return true;
        }
        return false;
    }

    public static Boolean isInteraction(String desc) {
        RuleType[] ts = RuleType.values();
        if (INTERACTION.getDesc().contains(desc)) {
            return true;
        }
        return false;
    }

    public static RuleType getRuleType(String code) {
        RuleType[] ts = RuleType.values();
        for (RuleType t : ts) {
            if (t.getCode().equalsIgnoreCase(code)) {
                return t;
            }
        }
        return OTHER;
    }

    public static RuleType getRuleTypeByDesc(String desc) {
        RuleType[] ts = RuleType.values();
        for (RuleType t : ts) {
            if (t.getDesc().contains(desc)) {
                return t;
            }
        }
        return OTHER;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getNum() {
        return num;
    }
}
